﻿using MySql.Data.MySqlClient;

namespace CatUtils.Utils.SpecialUtils.DataTool.Mysql
{
    /// <summary>
    /// mysql用户信息方法
    /// </summary>
    public class MysqlConfig
    {
        /// <summary>
        /// 初始化用户信息 指定数据库
        /// </summary>
        /// <returns></returns>
        public MySqlConnection ConnectionInit(string DataBaseName)
        {
            return ConnectionInit(DataBaseName, "localhost", 3306, "root", "root");
        }

        /// <summary>
        /// 初始化用户信息 不指定数据库，创建时使用
        /// </summary>
        /// <returns></returns>
        public MySqlConnection ConnectionInit()
        {
            return ConnectionInit("", "localhost", 3306, "root", "root");
        }

        /// <summary>
        /// 初始化用户信息
        /// </summary>
        /// <param name="DataBaseName"></param>
        /// <param name="DataSource"></param>
        /// <param name="DataPort"></param>
        /// <param name="DataUserName"></param>
        /// <param name="DataUserPass"></param>
        /// <returns></returns>
        public MySqlConnection ConnectionInit(string DataBaseName, string DataSource, int DataPort, string DataUserName, string DataUserPass)
        {
            string connStr = string.Format("Database={0};datasource={1};port={2};user={3};pwd={4};SslMode = none;", DataBaseName, DataSource, DataPort, DataUserName, DataUserPass);

            MySqlConnection conn = new MySqlConnection(connStr);

            return conn;
        }
    }
}